<?php
include('../mysqli_connect.php');
$sqlShooter = "select player_name,player_score from player ORDER BY player_score desc LIMIT 5;";
$resShooter = mysqli_query($dbc, $sqlShooter);
$Shooter = array();
$i = 0;
while ($row = mysqli_fetch_row($resShooter)) {
  $Shooter[$i]['name'] = $row[0];
  $Shooter[$i]['value'] = $row[1];
  $i = $i + 1;
}

$sqlHeight = "select player_name,height from player where player_id<>100 limit 15;";
$resHeight = mysqli_query($dbc, $sqlHeight);
$heightArray = array();
$i = 0;
while ($row = mysqli_fetch_row($resHeight)) {
  $heightArray[$i]['name'] = $row[0];
  $heightArray[$i]['value'] = $row[1];
  $i = $i + 1;
}

$avgSql = "select avg(height) avg from player where player_id<>100;";
$resAvg = mysqli_query($dbc, $avgSql);
$result = mysqli_fetch_assoc($resAvg);

$sqlAge = "select player_name,player_age from player where player_id<>100 limit 10;";
$resAge = mysqli_query($dbc, $sqlAge);
$ageArray = array();
$i = 0;
while ($row = mysqli_fetch_row($resAge)) {
  $ageArray[$i]['name'] = $row[0];
  $ageArray[$i]['value'] = $row[1];
  $i = $i + 1;
}


$response = array('status' => true, 'shooter' => $Shooter, 'height' => $heightArray, 'avg' => $result, 'age' => $ageArray);
echo json_encode($response);
